FROM debian:bookworm

WORKDIR /explain

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
    apt-get install -y libmojolicious-perl \
                libemail-sender-perl \
                libdate-simple-perl \
                libemail-valid-perl \
                libxml-simple-perl  \
                libdbd-pg-perl \
                libmodule-build-perl \
                libyaml-perl \
                libjson-perl \
                libclone-perl \
                libtest-deep-perl \
                libtest-exception-perl \
                libnumber-bytes-human-perl \
                pgformatter \
                curl \
                build-essential \
                cpanminus

RUN cpanm Pg::Explain

WORKDIR /tmp
RUN curl https://gitlab.com/depesz/pg-sql-prettyprinter/-/archive/main/pg-sql-prettyprinter-main.tar.bz2 -o pg-sql-prettyprinter-main.tar.bz2 && \
    tar xjvf pg-sql-prettyprinter-main.tar.bz2 && \
    cd pg-sql-prettyprinter-main && \
    perl Build.PL && \
    ./Build && \
    ./Build test && \
    ./Build install
WORKDIR /explain

COPY docker/explain.json explain.pl ./

RUN mkdir -p /explain/log/
RUN touch /explain/log/development.log

ENTRYPOINT /explain/explain.pl daemon
